Skip to content

fix(slack-agent): bump max steps + force synthesis when budget exhausted#31

Merged
TS00 merged 2 commits intodevfrom
fix/slack-agent-max-steps-synthesis
Apr 29, 2026
Merged

fix(slack-agent): bump max steps + force synthesis when budget exhausted#31
TS00 merged 2 commits intodevfrom
fix/slack-agent-max-steps-synthesis

Conversation

@TS00
Copy link
Copy Markdown
Collaborator

@TS00 TS00 commented Apr 29, 2026

Caught from prod logs immediately after Phase 4 shipped. The user hit a tool-budget cliff (12 tool calls, 6 steps, stop_reason=tool_use), the loop exited without text, and we fell back to "I couldn't produce a reply this turn" — which looks like a hard failure to the user.

Two changes:

  1. Bump MAX_AGENT_STEPS 6 → 10 (most turns finish in 0-2 steps; 6 was tight for fan-outs).

  2. When the loop exits without text (still in tool_use OR no text content), force one more call with tool_choice: { type: "none" } so the model must write a final answer from what it has. Includes synthetic tool_results stubs for any unanswered tool_uses (Anthropic requires them paired before the next user turn).

Audit metadata now reports stop_reason='synthesised_after_max_steps' so we can spot these turns in event review.

Existing 21 agent tests still green. The new path is a small extension of the same Anthropic-SDK call pattern; happy to add a dedicated test in a follow-up but shipping fast since prod is live.

Made with Cursor

TS00 added 2 commits April 28, 2026 20:58
User hit a tool-budget cliff on prod: a question that fanned out to 12
tool calls / 6 agent steps maxed out MAX_AGENT_STEPS, the loop exited
with stop_reason='tool_use' (still wanting to call more tools), and the
final response had no text blocks. We fell back to "I couldn't produce
a reply this turn — try rephrasing?" which looks like a hard failure.

Two changes:

1. Bump MAX_AGENT_STEPS 6 -> 10. Most turns end in 0-2 steps; 6 was a
   tight default for hand-authored answers that fan out across multiple
   read tools.

2. When the loop exits without text (either still in tool_use or just
   no text content for any reason), force ONE more API call with
   tool_choice: { type: "none" } so the model has to write a final
   answer using whatever it already has. The nudge tells it the tool
   budget is exhausted and to be honest if it doesn't have enough.

   Anthropic requires every tool_use to be paired with a tool_result
   before the next user turn, so before the nudge we append synthetic
   tool_results saying "tool budget exhausted" for any unanswered
   tool_uses from the model's last turn. Otherwise the API rejects
   the synthesis call.

Audit metadata now reports stop_reason='synthesised_after_max_steps'
for these turns so we can spot them in event review without grepping
logs.

Caught from prod logs after Phase 4 ship — exact symptom: 12 tools / 6
steps / stop=tool_use / reply_ok=1 (the apology was posted, not the
intended answer).

Made-with: Cursor
@TS00 TS00 merged commit e273f83 into dev Apr 29, 2026
4 checks passed
@TS00 TS00 deleted the fix/slack-agent-max-steps-synthesis branch April 29, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant